#pragma once
#include "GSE_CSession.h"

namespace GSE
{
	class CThreadPool;
	class CListener : public enable_shared_from_this<CListener>, public IListener
	{
		typedef std::set<CSession::pointer> SessionPool;
	public:
		typedef boost::shared_ptr<CListener> pointer;

	public:
		CListener(CThreadPool * );
		virtual ~CListener();

		virtual void SetSessionManager(ISessionManager * lpSessionManager);
		virtual void AsyncListen(const char * strIP, const char * strPort);
		virtual void Cancel();
		void CloseSession(CSession::pointer lpSession);
		virtual uint Run();
	private:
		void AsyncAccpet();
		void OnAccept(CSession::pointer lpSession,const system::error_code& errCode);

	private:
		CThreadPool *		m_lpThreadPool;
		ISessionManager *	m_lpSessionManager;
		ip::tcp::acceptor	m_Acceptor;
		SessionPool			m_Sessions;
	};
}